package etnorservice.etnor_service.service;

import etnorservice.etnor_service.domain.RoleDomain;
import etnorservice.etnor_service.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2025/03/24/14:45
 **/
@Service
public class RoleService {

    @Autowired
    private RoleMapper roleMapper;

    public List<RoleDomain> getRoleList() {
        return roleMapper.selectList(null);
    }

    @Transactional
    public RoleDomain addRole(RoleDomain role) {
        role.setCreatedAt(new Date());
        role.setUpdatedAt(new Date());
        roleMapper.insert(role);
        return role;
    }

    @Transactional
    public void updateRole(RoleDomain role) {
        role.setUpdatedAt(new Date());
        roleMapper.updateById(role);
    }

    @Transactional
    public void deleteRole(Integer id) {
        roleMapper.deleteById(id);
    }

    public RoleDomain getRole(Integer id) {
        return roleMapper.selectById(id);
    }
}